package com.Questions.hash;

import java.util.*;

/**
 * 多数元素2
 */
public class leetcode229 {
    public List<Integer> majorityElement(int[] nums) {
        int n=nums.length/3;
        Map<Integer,Integer> hash=new HashMap<>();
        for(int num:nums){
            hash.put(num,hash.getOrDefault(num,0)+1);
        }
        ArrayList<Integer> list=new ArrayList<>();
        for(Map.Entry<Integer,Integer> me:hash.entrySet()){
            int count=me.getValue();
            if(count>n){
                list.add(me.getKey());
            }
        }
        return list;
    }
}
